package likou;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2023/04/24 21:25
 */
public class _1163 {
    public String lastSubstring(String s) {
        List<Integer> indexList = new ArrayList<>();
        char max = 'A';
        for(int i =0;i<s.length();i++){
            char current= s.charAt(i);
            if(max<current){
                max = current;
                int finalI = i;
                indexList = new ArrayList<Integer>(){{add(finalI);}};
            }else if(max == current){
                indexList.add(i);
            }
        }
        String res = "";
        for(int i:indexList){
            String current = s.substring(i);
            if(current.compareTo(res)>0){
                res = current;
            }
        }
        return res;
    }
}
